;(function ($, ECar) {
    "use strict";
//首页焦点图
    var sliderNavRedbg = $('.bannerbox span.redbg'),
        spanRedbg = $('.bannerbox span.redbg'),
        bannerbox = $('.bannerbox');
    var j_dialog_close = $(".j_dialog-close"),
        info = $(".info"),
        mask = $("#mask"),
        exp_dialog = $("#exp-dialog"),
        scroll_content = $("#notice .scroll-content");

    var flexArr = [
        {
            obj: $('.listLider'),
            name: 'listLider',
            param: {
                selector: ".scroll > li.item",
                animation: 'slide',// 必备参数，自动滑动
                itemWidth: 230,// 定义每个item宽度，单位为px，默认为 100%
                customDirectionNav: $('.list_nav li.prev,.list_nav li.next'),
                before: function () {
                    $(".listLider .flex-viewport img").trigger("sporty");
                }
            }
        },
        {
            obj: $('.recommedbox'),
            name: 'recommedbox',
            param: {
                selector: ".list > li.item",
                animation: 'slide',// 必备参数，自动滑动
                itemWidth: 220,//定义每个item宽度，单位为px，默认为 100%
                controlNav: false,// 是否显示滑动控制小圆点，默认为 true
                customDirectionNav: $('.controls span.prev,.controls span.next')
            }

        },
        {
            obj: $('.roll-list'),
            name: 'roll-list',
            number: $('.roll-list img').size(),
            param: {
                selector: ".data-list > li",
                slideshow: false,
                animation: 'slide',// 必备参数，自动滑动
                move: 1,
                itemWidth: 180,// 定义每个item宽度，单位为px，默认为 100%
                controlNav: false,// 是否显示滑动控制小圆点，默认为 true
                customDirectionNav: $('.tab-item .prev,.tab-item .next')
            }
        },
        {
            obj: bannerbox,
            name: 'bannerbox',
            param: {
                selector: ".slidermain > .slider",
                controlNav: true,// 是否显示滑动控制小圆点，默认为 true
                directionNav: false,// 是否显示左右滑动控制控件，默认为 true
                manualControls: $('.slider-nav span.item'),
                eventType: 'click touchend MSPointerUp keyup mouseenter',
                start: function () {
                    sliderNavRedbg.parent().eq(0).addClass('flex-active');
                    setAnimate();
                },
                after: function (data) {
                    setAnimate();

                }
            }
        }
    ];

    var pointLider = function (i) {
        return {
            obj: $('.pointLider').eq(i),
            param: {
                namespace: 'pointLider-',
                slideshow: false,
                animation: 'slide',// 必备参数，自动滑动
                itemWidth: 270,// 定义每个item宽度，单位为px，默认为 100%
                controlNav: true,// 是否显示滑动控制小圆点，默认为 true
                directionNav: false,// 是否显示左右滑动控制控件，默认为 true
                eventType: 'click touchend MSPointerUp keyup mouseenter',
                manualControls: $('.pointLider').eq(i).find('.slider-nav li')
            }
        }
    }


    function flexInit(arr) {
        for (var i = 0, len = arr.length; i < len; i++) {
            if ((arr[i]['name'] == "roll-list" && arr[i].number > 6) || arr[i]['name'] != "roll-list") {
                arr[i].obj.flexslider(arr[i].param);
            }
        }
    }

    function flexPointLider() {
        for (var i = 0, len = 3; i < len; i++) {
            pointLider(i).obj.flexslider(pointLider(i).param);
        }
    }

    flexInit(flexArr);
    flexPointLider();

    function setAnimate() {
        spanRedbg.css('width', '0');
        $('.flex-active span.redbg').animate({
            width: '100%'
        }, 6000);
    }

    var controlsSpan = $('.controls span');
    controlsSpan.hover(function () {
        $(this).addClass('jello');
    }, function () {
        $(this).removeClass('jello');
    });


// tab切换
    ECar.tab({
        selector: "#tabs",
        event: "mouseover",
        delay: 200,
        selected: '.active',
        callback: function () {
            $("#tabstwo img").trigger("sporty");
            if ($(this).attr("id") != 'tabs') {
                pointLider(3).obj.flexslider(pointLider(3).param);
            }
        }
    });

    info.find("a").on("click", function () {
        $.get($(this).attr("data-href"), function (data) {
            scroll_content.removeAttr('style');
            scroll_content.html(data);
            mask.show();
            exp_dialog.show(function () {
            });
            scroll_content[0].scrollTop = 0;
        });
    });
    j_dialog_close.on("click", function () {
        mask.hide();
        exp_dialog.hide();
    });
// translate
    var fnTranslateY = function (a, b) {
            a.stop().animate({
                marginTop: b
            }, 300)
        }
        ;
    if (!document.addEventListener) {
        var j = $(".js_translateY");
        var h;
        j.each(function () {
            h = $(this);
            h.mouseover(function () {
                fnTranslateY($(this), -5)
            }).mouseout(function () {
                fnTranslateY($(this), 0)
            })
        });
    }

    $("img:not(.categorys-detail .brand img, .floor .flex-viewport)").lazyload({
        effect: "fadeIn"
    });
    $(".floor .floorOne").lazyload({
        effect: "fadeIn"
    });
    $(".listLider .flex-viewport img, #tabstwo img").lazyload({
        effect: "fadeIn",
        event: "sporty"
    });
    $(".floorone .floor .listLider img").lazyload({
        effect: "fadeIn"
    });


    function opensoon() {
        $(".data-list li").mouseover(function () {
            $(this).find('.open-soon').show();
        });
        $(".data-list li").mouseout(function () {
            $(this).find('.open-soon').hide();
        })
    }

    opensoon();
})(jQuery, window.ECar || (window.ECar = {}));